﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SolverFoundation.Common;
using Microsoft.SolverFoundation.Solvers;
using Microsoft.SolverFoundation.Services;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*SolverContext context = SolverContext.GetContext();
            Model model = context.CreateModel();
            Decision vz = new Decision(Domain.RealNonnegative, "barrels_venezuela"); //Real Kieu gia tri cua bien (so thuc)
            Decision sa = new Decision(Domain.RealNonnegative, "barrels_saudiarabia");
            model.AddDecisions(vz, sa);
            model.AddConstraints("limits",0 <= vz <= 9000,0 <= sa <= 6000);
            String string1, string2, string3;
            /*string1 = 0.3 * sa + 0.4 * vz >= 2000;
            string2 = 0.4 * sa + 0.2 * vz >= 1500;
            string3 = 0.2 * sa + 0.3 * vz >= 500;
            model.AddConstraints("pr", string1, string2, string3);
            /*model.AddConstraint("pr1", 0.3 * sa + 0.4 * vz >= 2000);
            model.AddConstraint("pr2", 0.4 * sa + 0.2 * vz >= 1500);
            model.AddConstraint("pr3", 0.2 * sa + 0.3 * vz >= 500);
             
            model.AddConstraints("production", 0.3 * sa + 0.4 * vz >= 2000, 0.4 * sa + 0.2 * vz >= 1500, 0.2 * sa + 0.3 * vz >= 500);
            model.AddGoal("cost", GoalKind.Minimize,20 * sa + 15 * vz);
            Solution solution = context.Solve(new SimplexDirective());

            //Report report = solution.GetReport();
            MessageBox.Show(vz.ToString()+" , "+sa.ToString());*/
            SimplexSolver solver = new SimplexSolver();
            int savid, vzvid;
            solver.AddVariable("Saudi Arabia", out savid);
            solver.SetBounds(savid, 0, 9000);
            solver.AddVariable("Venezuela", out vzvid);
            solver.SetBounds(vzvid, 0, 6000);
            int gasoline, jetfuel, machinelubricant, cost;
            solver.AddRow("gasoline", out gasoline);
            solver.AddRow("jetfuel", out jetfuel);
            solver.AddRow("machinelubricant", out machinelubricant);
            solver.AddRow("cost", out cost);
            solver.SetCoefficient(gasoline, savid, 0.3);
            solver.SetCoefficient(gasoline, vzvid, 0.4);
            solver.SetBounds(gasoline, 2000, Rational.PositiveInfinity);
            solver.SetCoefficient(jetfuel, savid, 0.4);
            solver.SetCoefficient(jetfuel, vzvid, 0.2);
            solver.SetBounds(jetfuel, 1500, Rational.PositiveInfinity);
            solver.SetCoefficient(machinelubricant, savid, 0.2);
            solver.SetCoefficient(machinelubricant, vzvid, 0.3);
            solver.SetBounds(machinelubricant, 500, Rational.PositiveInfinity);
            solver.SetCoefficient(cost, savid, 20);
            solver.SetCoefficient(cost, vzvid, 15);
            solver.AddGoal(cost, 1, true);
            solver.Solve(new SimplexSolverParams());
            MessageBox.Show(solver.GetValue(savid).ToDouble().ToString() + "," + solver.GetValue(vzvid).ToDouble().ToString());


           

        }
    }
}
